<?php 
// Header

$this->set('title_for_layout', __("Tạo sản phẩm mới", true));

$this->left_menu = 'menu/'.$this->params['controller'];
$params = array(
	'root'	=>	$this->params['named']['root']
);

echo $this->Html->css('/products/css/jstree/tree_component');
// -- Load CSS : End  --

// Load Javascript
echo $this->Html->script('ckeditor/ckeditor_basic');
//echo $this->Html->script('jquery.form');
echo $this->Html->script('/products/js/add');

if (count($categories)):
echo $this->Html->script('jstree/jquery.tree');
echo $this->Html->script('jstree/plugins/jquery.tree.checkbox');
echo $this->Html->script('jstree/libs/_lib');
endif;
?>
<style>
#dialogs {
	display:none;
}
</style>
<script language="javascript">
$(document).ready(function () {
	<?php if (count($categories)):?>
	the_tree = $("#category_tree").tree({
		ui : {
			theme_name : "checkbox",
			theme_path : "<?php echo $html->url('/css/jstree/themes/checkbox/style.css')?>"
		},
		plugins : { 
			checkbox : { }
		}
	});
	<?php endif;?>
	var select_categories_div = $('div#select_categories');
	select_categories_div.dialog({
		resizable: false,
		width: 400,
		autoOpen: false,
		modal: true
	});

	$('a#select_categories_link').click(function() {
		select_categories_div.dialog('open');
	});

	var the_form = $('form#add_page_form');
	the_form.find('div.submit input[type="submit"]').click(function() {
		$('div#category_tree a.checked').each(function() {
			var check_id = $(this).parent().attr('node_id');
			the_form.append($("<input type='hidden' name='data[Category][]' value='"+check_id+"'/>"));
		});
	});

	
	$('div#select_categories div.button_panel input[type="button"]').click(function() {
		select_categories_div.dialog('close');
	});
});

</script>
<h2><?php __("Tạo sản phẩm mới")?></h2>
<?php echo $session->flash()?>

<div class="buttons attop">
	<ul>
		<li><a href="<?php echo $html->url($params + array('action'	=>	'index'))?>" class="back"><?php __("Danh sách sản phẩm")?></a></li>
		<li><a href="javascript:void(0)" class="save"><?php __("Thêm mới")?></a></li>
	</ul>
</div>

<?php 
echo $form->create('Product', array(
	'url'	=>	
	$params + array(
		'controller'	=>	$this->params['controller'],	
		'action'		=>	'add'
	),
	'id'		=>	'add_page_form',
	'enctype'	=>	'multipart/form-data'
));
?>
<fieldset class="form">

<?php 
echo $form->input('title', array(
	'label'	=>	__("Tiêu đề: <font color=\"red\">(*)</font>", true),
	'error'	=>	__("Tiêu đề bài viết không được để trống", true),
	'size'	=> 50
));

if ($configs['Manage']['add']['show_alias']) {
	echo $form->input('alias', array('label'	=>	__("Alias: ", true)));
} else {
	echo $form->input('alias', array('label'	=>	__("Alias: ", true), 'type' => 'hidden'));
}

if ($configs['Product']['image']['show']):
$options = array(
	//'name'				=>	$this->data['Article']['image'],
	'name'				=>	'',
	'path'				=>	'',
	'field_name'		=>	'image',
	'label'				=>	__('&nbsp;',true),
	'legend_title'		=>	__('Hình ảnh',true),
	'delete_image_link'	=>	''
);
echo $html->form_image($options,array());
endif;
?>
<?php if ($configs['Product']['description']['show']):?>
<div class="input">
<table cellpadding='0' cellspacing='0' border='0' width='100%' class='list-table'>
<tr>
	<td class='label' valign='top'><label for="description"><?php __("Mô tả")?></label></td>
	<td>
		<?php
		echo $form->input('description', array('label'	=>	false, 'div'=>false, 'type'=>'textarea', 'value'	=>	$configs['Product']['description']['default_content'])); 
		
		if (!isset($configs['Product']['description']['use_rich_text']) || $configs['Product']['description']['use_rich_text']):
		echo $wysiwyg->render("Product.description", 'ckeditor', $configs['Product']['description_config']);
		endif;
		
		?>
	</td>
</tr>
</table>
</div>
<?php endif;?>

<?php if ($configs['Product']['content']['show']):?>
<div class="input">
<table cellpadding='0' cellspacing='0' border='0' width='100%' class='list-table'>
<tr>
	<td class='label' valign='top'><label for="content"><?php __("Nội dung: ")?></label></td>
	<td>
		<?php
		echo $form->input('content', array('label'	=>	false, 'div'=>false, 'type'=>'textarea', 'value' => $configs['Product']['content']['default_content'])); 
		
		if (!isset($configs['Product']['description']['use_rich_text']) || $configs['Product']['description']['use_rich_text']):
		echo $wysiwyg->render("Product.content", 'ckeditor', $configs['Product']['content_config']);
		endif;
		?>
	</td>
</tr>
</table>
</div>
<?php endif;?>
<?php
echo $form->input('price', array(
	'label'	=>	__("Giá: ", true),
	'size'	=> 50,
    'default'   => '1.000.000 VND'
));

?>			
<?php if (count($categories)):?>
<div class='input text'>
	<label>&nbsp;</label>
	[ <a href='javascript:void(0)' id='select_categories_link'><?php __("Bấm vào đây để chọn danh mục")?></a> ]
</div>
<?php else:?>
<?php echo $form->input('Category', array('type'=>'hidden', 'value' => $category_root_id, 'name'=>"data[Category][]"))?>
<?php endif;?>

<div id='dialogs'>
<div id='select_categories' title="<?php __("Chọn danh mục")?>" class='form'>
<?php 
$settings = array(
	'data'			=>	$categories,
	'expand_all'	=>	true,
	'attributes'	=>	array(
		'id'	=>	'category_tree',
		'class'	=>	'demo'
	),
	'fields'		=>	array(
		'text'	=>	'name',
		'id'	=>	'id'
	),
	'model'	=>	'ProductCategory'
);
echo $this->element('tree/jstree_checkbox', array('settings'	=>	$settings));?>

<div align='center' class='button_panel submit'>
	<input type='button' class='button' value='<?php __(" Đóng ")?>'/> 
</div>

</div>
</div>
<?php
echo $form->input('is_published', array('label' => __("Kích hoạt?", true), 'checked' => "checked"));
if ($configs['Product']['special']['show']):
    echo $form->input('special', array('label' => __("Sản phẩm đặc biệt?", true)));
endif;
?>
<div style="display:none">
	<input type="submit"/>
</div>
</fieldset>
<?php echo $form->end();?>
<div class="buttons attop">
	<ul>
		<li><a href="<?php echo $html->url($params + array('action'	=>	'index'))?>" class="back"><?php __("Danh sách sản phẩm")?></a></li>
		<li><a href="javascript:void(0)" class="save"><?php __("Thêm mới")?></a></li>
	</ul>
</div>